<template>
  <el-dialog
    :title="title"
    center
    :visible.sync="openState"
    width="1024px"
    :close-on-click-modal="false"
    :before-close="handleClose"
  >
    <!-- 新增录入画面对话框-->
    <card-form
      ref="cardForm"
      :title="title"
      :openState="openState"
      :dictMap="dictMap"
      :cardList="cardList"
      :formData="form"
      :confirmPayerCallback="confirmPayer"
      :confirmPayeeCallback="confirmPayee"
      :confirmBankBranchCallback="confirmBankBranch"
    ></card-form>

    <div slot="footer" class="dialog-footer">
      <el-button type="primary" @click="submitForm(null)">提交</el-button>
      <el-button @click="cancel">取消</el-button>
    </div>
  </el-dialog>
</template>
<script>
import {addTxn, updTxn, submitCheckBlackAndAmount} from "@/api/cnaps/baseBiz/send/hvps/hvps.js";
import {detail, delTxn} from "@/api/cnaps/baseBiz/send/sendCommon.js";
import {getOtherCustByActno, getCustByActno} from "@/api/cnaps/common/custInfo";
import {getBankInfByBankCode} from "@/api/cnaps/common/bankInfo";
import {isLessThenHvpsMinLimitNew} from "@/api/cnaps/common/cp2SysParam";
import CardForm from "@/views/components/CardForm";
import {mapGetters} from "vuex";

export default {
  name: "EditInfo",
  components: {
    CardForm,
  },
  props: {
    dictMap: {
      type: Object,
      default: () => {
        return {};
      },
    },
  },
  data() {
    return {
      cardList: [],
      busTypeList: [],
      id: "",
      title: "",
      pkgNo: "",
      // 是否显示弹出层
      openState: false,
      // 表单参数
      form: {
        amount: "0.00",
      },
    };
  },
  watch: {
    dictMap: {
      handler(data) {
      },
    },
  },
  computed: {
    ...mapGetters(["globalBusData"]),
  },
  async mounted() {
    let that = this;
    const bizType111List = await this.getDicts("BIZ_TYPE_111").then((res) => {
      return res.result;
    });
    this.$set(this.form, "bizTypeCode", bizType111List[0].value);
    this.busTypeList = await this.getDicts(`BIZ_CTGY_HVPS_${bizType111List[0].value}`).then((res) => {
      return res.result;
    });

    let formConfigList = [
      {
        name: "交易基础信息",
        ref: "baseInfo",
        rules: {
          amount: [
            {
              required: true,
              message: "请填写交易金额",
            },
          ],
        },
        rowColNum: 3,
        labelWidth: "100px",
        hide: false,
        formItemList: [
          {
            type: "dict",
            dict: "BIZ_TYPE_111",
            prop: "bizTypeCode",
            defaultAttr: {
              label: "业务类型",
              placeholder: "请选择业务类型",
              defaultValue: bizType111List[0].value,
            },
            linkedRules: [
              {
                ruleType: "callbackFn",
                callback: (item, form, formListOptions, rowData, initFlag, formDiarules) => {
                  //联动修改bizCtgyCode
                  let dictKeyPre = `BIZ_CTGY_HVPS_${form["bizTypeCode"]}`;
                  this.getDicts(dictKeyPre).then((response) => {
                    this.busTypeList = response.result;
                    formListOptions[1].selectOptionList = response.result.map((x) => {
                      return {label: x.text, value: x.value};
                    });
                    this.$set(form, "bizCtgyCode", this.busTypeList[0].value);
                  });
                  let bizTypeCode = form["bizTypeCode"];
                  if (bizTypeCode) {
                    console.log("temp", bizTypeCode);
                    // 委托收款
                    if (bizTypeCode === "A109") {
                      let temp = that.cardList.find((x) => x.ref === "entrustInfo");
                      if (temp && temp.hide) {
                        temp.hide = false;
                      }
                    } else {
                      let temp = that.cardList.find((x) => x.ref === "entrustInfo");
                      if (temp && !temp.hide) {
                        temp.hide = true;
                      }
                    }

                    // 托收承付
                    if (bizTypeCode === "A110") {
                      let temp = that.cardList.find((x) => x.ref === "prepayment");
                      if (temp && temp.hide) {
                        temp.hide = false;
                      }
                    } else {
                      let temp = that.cardList.find((x) => x.ref === "prepayment");
                      if (temp && !temp.hide) {
                        temp.hide = true;
                      }
                    }

                    if (bizTypeCode === "A111") {
                      let temp = that.cardList.find((x) => x.ref === "commercialDraft");
                      if (temp && temp.hide) {
                        temp.hide = false;
                      }
                    } else {
                      let temp = that.cardList.find((x) => x.ref === "commercialDraft");
                      if (temp && !temp.hide) {
                        temp.hide = true;
                      }
                    }

                    if (bizTypeCode === "A113") {
                      let temp = that.cardList.find((x) => x.ref === "crossPayment");
                      if (temp && temp.hide) {
                        temp.hide = false;
                      }
                    } else {
                      let temp = that.cardList.find((x) => x.ref === "crossPayment");
                      if (temp && !temp.hide) {
                        temp.hide = true;
                      }
                    }

                    if (bizTypeCode === "A201") {
                      let temp = that.cardList.find((x) => x.ref === "cheque");
                      if (temp && temp.hide) {
                        temp.hide = false;
                      }
                    } else {
                      let temp = that.cardList.find((x) => x.ref === "cheque");
                      if (temp && !temp.hide) {
                        temp.hide = true;
                      }
                    }

                    if (bizTypeCode === "A202") {
                      let temp = that.cardList.find((x) => x.ref === "draft");
                      if (temp && temp.hide) {
                        temp.hide = false;
                      }
                    } else {
                      let temp = that.cardList.find((x) => x.ref === "draft");
                      if (temp && !temp.hide) {
                        temp.hide = true;
                      }
                    }

                    if (bizTypeCode === "A203") {
                      let temp = that.cardList.find((x) => x.ref === "bankDraft");
                      if (temp && temp.hide) {
                        temp.hide = false;
                      }
                    } else {
                      let temp = that.cardList.find((x) => x.ref === "bankDraft");
                      if (temp && !temp.hide) {
                        temp.hide = true;
                      }
                    }

                    if (bizTypeCode === "A204") {
                      let temp = that.cardList.find((x) => x.ref === "bankSelfDraft");
                      if (temp && temp.hide) {
                        temp.hide = false;
                      }
                    } else {
                      let temp = that.cardList.find((x) => x.ref === "bankSelfDraft");
                      if (temp && !temp.hide) {
                        temp.hide = true;
                      }
                    }

                    //画面输入要素修改------------------
                    if (bizTypeCode == "A202" && that.$refs.cardForm) {
                      //城市商业银行汇票
                      that.$refs.cardForm.formData["payeeBrno"] = "904290099992";
                      that.$refs.cardForm.formData["payeeAccBrno"] = "904290099992";
                      that.$refs.cardForm.$refs.payeeInfo[0].form["payeeBrno"] = "904290099992";
                      that.$refs.cardForm.$refs.payeeInfo[0].form["payeeName"] = "城银清算服务有限责任公司";
                      that.$refs.cardForm.$refs.payeeInfo[0].form["payeeAccBrno"] = "904290099992";
                      that.$refs.cardForm.$refs.payeeInfo[0].form["payeeAccBrName"] = "城银清算服务有限责任公司";

                      that.$refs.cardForm.$refs.payeeInfo[0].formDiarules["payeeActno"][0].required = false;
                      that.$refs.cardForm.$refs.payeeInfo[0].formDiarules["payeeName"][0].required = false;
                      that.$refs.cardForm.$refs.payeeInfo[0].formDiarules["payeeAccBrno"][0].required = false;
                    }
                    if (bizTypeCode !== "A202" && that.$refs.cardForm) {
                      this.$nextTick(() => {
                        that.$refs.cardForm.$refs.payeeInfo[0].formDiarules["payeeActno"][0].required = true;
                        that.$refs.cardForm.$refs.payeeInfo[0].formDiarules["payeeName"][0].required = true;
                        that.$refs.cardForm.$refs.payeeInfo[0].formDiarules["payeeAccBrno"][0].required = true;
                      });
                    }
                  }
                },
              },
            ],
          },
          {
            type: "select",
            prop: "bizCtgyCode",
            defaultAttr: {
              label: "业务种类",
              placeholder: "请选择业务种类",
            },
            selectOptionList: this.busTypeList.map((x) => {
              return {label: x.text, value: x.value};
            }),
          },
          {
            type: "dict",
            dict: "PRIORITY3CODE",
            prop: "bizPriority",
            defaultAttr: {
              label: "业务优先级",
              placeholder: "请选择业务优先级",
            },
            linkedRules: [
              {
                ruleType: "callbackFn",
                callback: (item, form, formListOptions, rowData, initFlag, formDiaRules) => {
                  this.$nextTick(() => {
                    if (!form["bizPriority"]) {
                      that.$refs.cardForm.$refs.baseInfo[0].form["bizPriority"] = that.dictMap.PRIORITY3CODE[0].value;
                    }
                  });
                },
              },
            ],
          },
          {
            type: "input",
            prop: "transSource",
            defaultAttr: {
              label: "交易渠道",
              placeholder: "请填写交易渠道",
              disabled: true,
              defaultValue: "柜面交易",
            },
          },
          {
            type: "dict",
            dict: "CBFLAG",
            prop: "cbflag",
            defaultAttr: {
              label: "记账标志",
              placeholder: "请选择记账标志",
            },
            linkedRules: [
              {
                ruleType: "callbackFn",
                callback: (item, form, formListOptions, rowData, initFlag, formDiaRules) => {
                  this.$nextTick(() => {
                    if (!form["cbflag"]) {
                      that.$refs.cardForm.$refs.baseInfo[0].form["cbflag"] = that.dictMap.CBFLAG[0].value;
                    }
                  });
                },
              },
            ],
          },
          {
            type: "dict",
            dict: "CUST_FLAG1",
            prop: "custflag1",
            defaultAttr: {
              label: "账户类型",
              placeholder: "请选择账户类型",
            },
            linkedRules: [
              {
                ruleType: "callbackFn",
                callback: (item, form, formListOptions, rowData, initFlag, formDiaRules) => {
                  this.$nextTick(() => {
                    if (!form["custflag1"]) {
                      that.$refs.cardForm.$refs.baseInfo[0].form["custflag1"] = that.dictMap.CUST_FLAG1[0].value;
                    }
                  });
                },
              },
            ],
          },
          {
            type: "input",
            prop: "transCNY",
            defaultAttr: {
              label: "交易币种",
              placeholder: "请填写交易币种",
              disabled: true,
              defaultValue: "CNY",
            },
          },
          {
            type: "number",
            prop: "amount",
            className: "amount-input",
            defaultAttr: {
              label: "交易金额",
              placeholder: "请填写交易金额",
              defaultValue: 0.0,
            },
            linkedRules: [
              {
                ruleType: "callbackFn",
                callback: (item, form, formListOptions, rowData, initFlag, formDiarules) => {
                  if (that.$refs.cardForm) {
                    this.$nextTick(() => {
                      that.$refs.cardForm.$refs["upperAmount"][0].changeAmount(form[item.prop]);
                    });
                  }
                },
              },
            ],
          },
          {
            type: "slot",
            prop: "upperAmount",
            componentType: "HtAmountUpper",
            ref: "upperAmount",
            defaultAttr: {
              label: "大写金额",
            },
          },
        ],
      },
      {
        name: "付款人信息",
        ref: "payerInfo",
        rules: {
          payerActno: [
            {
              required: true,
              message: "请填写付款人账号",
            },
          ],
          payerName: [
            {
              required: true,
              message: "请填写付款人名称",
            },
          ],
          payerBrno: [
            {
              required: true,
              message: "请填写付款行行号",
            },
          ],
          payerBrName: [
            {
              required: true,
              message: "请填写付款行行名",
            },
          ],
          payerAccBrno: [
            {
              required: true,
              message: "请填写付款人开户行号",
            },
          ],
        },
        rowColNum: 4,
        labelWidth: "110px",
        hide: false,
        formItemList: [
          {
            type: "slot",
            prop: "payerActno",
            componentType: "selectAccount",
            defaultAttr: {
              label: "付款人账号",
              placeholder: "请填写付款人账号",
              colWidthCount: 2,
            },
            actNoInfoCallback: that.actNoInfoCallback,
          },
          {
            type: "input",
            prop: "payerName",
            defaultAttr: {
              label: "付款人名称",
              placeholder: "请填写付款人名称",
              colWidthCount: 4,
            },
          },
          {
            type: "input",
            prop: "payerAddr",
            defaultAttr: {
              label: "付款人地址",
              placeholder: "请填写付款人地址",
              colWidthCount: 4,
            },
          },
          {
            type: "slot",
            prop: "payerBrno",
            componentType: "selectBranch",
            defaultAttr: {
              label: "付款行行号",
              placeholder: "请填写付款行行号",
              colWidthCount: 2,
            },
            linkedRules: [
              {
                ruleType: "callbackFn",
                callback: (item, form, formListOptions, rowData, initFlag, formDiarules) => {
                  console.log(rowData, 1111);
                  if (rowData.id) {
                    this.$set(item.defaultAttr, "disabled", false);
                  } else {
                    this.$set(item.defaultAttr, "disabled", true);
                  }
                },
              },
            ],
            bankInfCallback: that.getBankInf,
          },
          {
            type: "input",
            prop: "payerBrName",
            defaultAttr: {
              label: "付款行行名",
              placeholder: "请填写付款行行名",
              colWidthCount: 2,
            },
            linkedRules: [
              {
                ruleType: "callbackFn",
                callback: (item, form, formListOptions, rowData, initFlag, formDiarules) => {
                  if (rowData.id) {
                    this.$set(item.defaultAttr, "disabled", false);
                  } else {
                    this.$set(item.defaultAttr, "disabled", true);
                  }
                },
              },
            ],
          },
          {
            type: "slot",
            prop: "payerAccBrno",
            componentType: "selectBranch",
            defaultAttr: {
              label: "付款人开户行号",
              placeholder: "请填写付款人开户行号",
              colWidthCount: 2,
            },
            bankInfCallback: that.getBankInf,
          },
          {
            type: "input",
            prop: "payerAccBrName",
            defaultAttr: {
              label: "付款人开户行行名",
              placeholder: "请填写付款人开户行行名",
              colWidthCount: 2,
            },
          },
        ],
      },
      {
        name: "收款人信息",
        ref: "payeeInfo",
        rules: {
          payeeActno: [
            {
              required: true,
              message: "请填写收款人账号",
            },
          ],
          payeeName: [
            {
              required: true,
              message: "请填写收款人名称",
            },
          ],
          payeeBrno: [
            {
              required: true,
              message: "请填写收款行行号",
            },
          ],
          payeeName: [
            {
              required: true,
              message: "请填写收款行行名",
            },
          ],
          payeeAccBrno: [
            {
              required: true,
              message: "请填写收款人开户行号",
            },
          ],
        },
        rowColNum: 4,
        labelWidth: "110px",
        hide: false,
        formItemList: [
          {
            type: "slot",
            prop: "payeeActno",
            componentType: "selectAccount",
            defaultAttr: {
              label: "收款人账号",
              placeholder: "请填写收款人账号",
              colWidthCount: 2,
            },
            actNoInfoCallback: that.actNoInfoCallback,
          },
          {
            type: "input",
            prop: "payeeName",
            defaultAttr: {
              label: "收款人名称",
              placeholder: "请填写收款人名称",
              colWidthCount: 4,
            },
          },
          {
            type: "input",
            prop: "payeeAddr",
            defaultAttr: {
              label: "收款人地址",
              placeholder: "请填写收款人地址",
              colWidthCount: 4,
            },
          },
          {
            type: "slot",
            prop: "payeeBrno",
            componentType: "selectBranch",
            defaultAttr: {
              label: "收款行行号",
              placeholder: "请填写收款行行号",
              colWidthCount: 2,
            },
            bankInfCallback: that.getBankInf,
          },
          {
            type: "input",
            prop: "payeeName",
            defaultAttr: {
              label: "收款行行名",
              placeholder: "请填写收款行行名",
              colWidthCount: 2,
            },
          },
          {
            type: "slot",
            prop: "payeeAccBrno",
            componentType: "selectBranch",
            defaultAttr: {
              label: "收款人开户行号",
              placeholder: "请填写付款人开户行号",
              colWidthCount: 2,
            },
            bankInfCallback: that.getBankInf,
          },
          {
            type: "input",
            prop: "payeeAccBrName",
            defaultAttr: {
              label: "收款人开户行行名",
              placeholder: "请填写收款人开户行行名",
              colWidthCount: 2,
            },
          },
        ],
      },
      {
        name: "其他交易信息",
        ref: "otherInfo",
        rules: {},
        rowColNum: 4,
        labelWidth: "110px",
        hide: false,
        formItemList: [
          {
            type: "slot",
            prop: "agency1",
            componentType: "selectBranch",
            defaultAttr: {
              label: "中介机构1",
              placeholder: "请填写中介机构1",
              colWidthCount: 2,
            },
            bankInfCallback: that.getBankInf,
          },
          {
            type: "input",
            prop: "agency1name",
            defaultAttr: {
              label: "中介机构1名称",
              placeholder: "请填写中介机构1名称",
              colWidthCount: 2,
            },
          },
          {
            type: "slot",
            prop: "agency2",
            componentType: "selectBranch",
            defaultAttr: {
              label: "中介机构2",
              placeholder: "请填写中介机构2",
              colWidthCount: 2,
            },
            bankInfCallback: that.getBankInf,
          },
          {
            type: "input",
            prop: "agency2name",
            defaultAttr: {
              label: "中介机构2名称",
              placeholder: "请填写中介机构2名称",
              colWidthCount: 2,
            },
          },
          {
            type: "textarea",
            prop: "remarks",
            defaultAttr: {
              label: "备注",
              placeholder: "请填写备注",
              colWidthCount: 4,
              maxlength: 140,
              showWordLimit: "show-word-limit"

            },
          },
          {
            type: "textarea",
            prop: "memo",
            defaultAttr: {
              label: "附言",
              placeholder: "请填写附言",
              colWidthCount: 4,
              maxlength: 210,
              showWordLimit: "show-word-limit"
            },
          },
        ],
      },
      {
        name: "委托收款 （划回）",
        ref: "entrustInfo",
        rules: {},
        rowColNum: 9,
        labelWidth: "100px",
        hide: true,
        formItemList: [
          {
            type: "date",
            prop: "clltnNotesDate",
            defaultAttr: {
              label: "票据日期",
              placeholder: "请填写票据日期",
              colWidthCount: 3,
            },
          },
          {
            type: "input",
            prop: "e2eId",
            defaultAttr: {
              label: "票据号码",
              placeholder: "请填写票据号码",
              colWidthCount: 3,
            },
          },
          {
            type: "input",
            prop: "clltnNotesType",
            defaultAttr: {
              label: "凭证种类",
              placeholder: "请填写凭证种类",
              colWidthCount: 3,
            },
          },
        ],
      },
      {
        name: "托收承付 （划回）",
        ref: "prepayment",
        rules: {},
        rowColNum: 9,
        labelWidth: "100px",
        hide: true,
        formItemList: [
          {
            type: "date",
            prop: "clltnNotesDate",
            defaultAttr: {
              label: "票据日期",
              placeholder: "请填写票据日期",
              colWidthCount: 3,
            },
          },
          {
            type: "input",
            prop: "e2eId",
            defaultAttr: {
              label: "票据号码",
              placeholder: "请填写票据号码",
              colWidthCount: 3,
            },
          },
          {
            type: "number",
            prop: "pmtPayAmount",
            defaultAttr: {
              label: "支付金额",
              placeholder: "请填写支付金额",
              colWidthCount: 3,
            },
          },
          {
            type: "number",
            prop: "pmtOriAmount",
            defaultAttr: {
              label: "原托金额",
              placeholder: "请填写原托金额",
              colWidthCount: 3,
            },
          },
          {
            type: "number",
            prop: "pmtRejectAmount",
            defaultAttr: {
              label: "拒付金额",
              placeholder: "请填写拒付金额",
              colWidthCount: 3,
            },
          },
          {
            type: "number",
            prop: "pmtAmendsAmount",
            defaultAttr: {
              label: "赔偿金额",
              placeholder: "请填写赔偿金额",
              colWidthCount: 3,
            },
          },
          {
            type: "number",
            prop: "pmtAddAmount",
            defaultAttr: {
              label: "多付金额",
              placeholder: "请填写多付金额",
              colWidthCount: 3,
            },
          },
        ],
      },
      {
        name: "商业汇票附加域信息",
        ref: "commercialDraft",
        rules: {},
        rowColNum: 9,
        labelWidth: "100px",
        hide: true,
        formItemList: [
          {
            type: "input",
            prop: "dftAppActno",
            defaultAttr: {
              label: "申请人账号",
              placeholder: "请填写申请人账号",
              colWidthCount: 3,
            },
          },
          {
            type: "input",
            prop: "dftAppName",
            defaultAttr: {
              label: "申请人名称",
              placeholder: "请填写申请人名称",
              colWidthCount: 3,
            },
          },
          {
            type: "date",
            prop: "dftDate",
            defaultAttr: {
              label: "票据日期",
              placeholder: "请填写票据日期",
              colWidthCount: 3,
            },
          },
          {
            type: "input",
            prop: "e2eId",
            defaultAttr: {
              label: "票据号码",
              placeholder: "请填写票据号码",
              colWidthCount: 3,
            },
          },
          {
            type: "number",
            prop: "dftAppActno",
            defaultAttr: {
              label: "出票金额",
              placeholder: "请填写出票金额",
              colWidthCount: 3,
            },
          },
          {
            type: "number",
            prop: "dftStAmt",
            defaultAttr: {
              label: "实际结算金额",
              placeholder: "请填写实际结算金额",
              colWidthCount: 3,
            },
          },
          {
            type: "number",
            prop: "dftOverAmt",
            defaultAttr: {
              label: "多余金额",
              placeholder: "请填写多余金额",
              colWidthCount: 3,
            },
          },
        ],
      },
      {
        name: "跨境支付附加域信息",
        ref: "crossPayment",
        rules: {},
        rowColNum: 6,
        labelWidth: "110px",
        hide: true,
        formItemList: [
          {
            type: "date",
            prop: "cbBizAssocBizDate",
            defaultAttr: {
              label: "关联业务委托日期",
              placeholder: "请填写关联业务委托日期",
              colWidthCount: 3,
            },
          },
          {
            type: "input",
            prop: "cbBizFeeCode",
            defaultAttr: {
              label: "费用编码",
              placeholder: "请填写费用编码",
              colWidthCount: 3,
            },
          },
          {
            type: "input",
            prop: "cbBizSndBnkFee",
            defaultAttr: {
              label: "发报行的收费",
              placeholder: "请填写发报行的收费",
              colWidthCount: 3,
            },
          },
          {
            type: "input",
            prop: "payAddInfo",
            defaultAttr: {
              label: "收报行的收费",
              placeholder: "请填写收报行的收费",
              colWidthCount: 3,
            },
          },
          {
            type: "textarea",
            prop: "cbBizRemark",
            defaultAttr: {
              label: "跨境业务附言",
              placeholder: "请填写跨境业务附言",
              colWidthCount: 6,
              maxlength: 135,
              showWordLimit: "show-word-limit"
            },
          },
        ],
      },
      {
        name: "支票附加域信息",
        ref: "cheque",
        rules: {},
        rowColNum: 6,
        labelWidth: "110px",
        hide: true,
        formItemList: [
          {
            type: "date",
            prop: "checkNotesDate",
            defaultAttr: {
              label: "出票日期",
              placeholder: "请填写出票日期",
              colWidthCount: 2,
            },
          },
          {
            type: "input",
            prop: "e2eId",
            defaultAttr: {
              label: "票据号码",
              placeholder: "请填写票据号码",
              colWidthCount: 2,
            },
          },
          {
            type: "input",
            prop: "checkAppName",
            defaultAttr: {
              label: "出票人名称",
              placeholder: "请填写出票人名称",
              colWidthCount: 2,
            },
          },
          {
            type: "number",
            prop: "checkNotesNum",
            defaultAttr: {
              label: "票据张数",
              placeholder: "请填写票据张数",
              colWidthCount: 2,
            },
          },
          {
            type: "number",
            prop: "checkNotesAmount",
            defaultAttr: {
              label: "票据金额",
              placeholder: "请填写票据金额",
              colWidthCount: 2,
            },
          },
          {
            type: "number",
            prop: "checkExchage",
            defaultAttr: {
              label: "牌价",
              placeholder: "请填写牌价",
              colWidthCount: 2,
            },
          },
        ],
      },
      {
        name: "汇票资金移存附加域信息",
        ref: "draft",
        rules: {},
        rowColNum: 6,
        labelWidth: "110px",
        hide: true,
        formItemList: [
          {
            type: "date",
            prop: "checkNotesDate",
            defaultAttr: {
              label: "出票日期",
              placeholder: "请填写出票日期",
              colWidthCount: 2,
            },
          },
          {
            type: "input",
            prop: "e2eId",
            defaultAttr: {
              label: "票据号码",
              placeholder: "请填写票据号码",
              colWidthCount: 2,
            },
          },
          {
            type: "input",
            prop: "dftKey",
            defaultAttr: {
              label: "汇票密押",
              placeholder: "请填写汇票密押",
              colWidthCount: 2,
            },
          },
          {
            type: "input",
            prop: "dftCtgy",
            defaultAttr: {
              label: "票据种类",
              placeholder: "请填写票据种类",
              colWidthCount: 2,
            },
          },
          {
            type: "input",
            prop: "dftPayBrno",
            defaultAttr: {
              label: "现金汇票兑付行",
              placeholder: "请填写现金汇票兑付行",
              colWidthCount: 2,
            },
          },
          {
            type: "input",
            prop: "dftPayerName",
            defaultAttr: {
              label: "收款人名称",
              placeholder: "请填写票面记载的收款人名称",
              colWidthCount: 6,
            },
          },
        ],
      },
      {
        name: "银行汇票附加域信息",
        ref: "bankDraft",
        rules: {},
        rowColNum: 6,
        labelWidth: "110px",
        hide: true,
        formItemList: [
          {
            type: "input",
            prop: "e2eId",
            defaultAttr: {
              label: "票据号码",
              placeholder: "请填写票据号码",
              colWidthCount: 2,
            },
          },
          {
            type: "date",
            prop: "checkNotesDate",
            defaultAttr: {
              label: "出票日期",
              placeholder: "请填写出票日期",
              colWidthCount: 2,
            },
          },
          {
            type: "input",
            prop: "dftAppActno",
            defaultAttr: {
              label: "申请人账号",
              placeholder: "请填写申请人账号",
              colWidthCount: 2,
            },
          },
          {
            type: "input",
            prop: "dftAppName",
            defaultAttr: {
              label: "申请人名称",
              placeholder: "请填写申请人名称",
              colWidthCount: 2,
            },
          },
          {
            type: "number",
            prop: "dftAppActno",
            defaultAttr: {
              label: "出票金额",
              placeholder: "请填写出票金额",
              colWidthCount: 2,
            },
          },
          {
            type: "number",
            prop: "dftStAmt",
            defaultAttr: {
              label: "实际结算金额",
              placeholder: "请填写实际结算金额",
              colWidthCount: 2,
            },
          },
          {
            type: "number",
            prop: "dftOverAmt",
            defaultAttr: {
              label: "多余金额",
              placeholder: "请填写多余金额",
              colWidthCount: 2,
            },
          },
        ],
      },
      {
        name: "银行本票附加域信息",
        ref: "bankSelfDraft",
        rules: {},
        rowColNum: 6,
        labelWidth: "110px",
        hide: true,
        formItemList: [
          {
            type: "input",
            prop: "e2eId",
            defaultAttr: {
              label: "票据号码",
              placeholder: "请填写票据号码",
              colWidthCount: 2,
            },
          },
          {
            type: "date",
            prop: "checkNotesDate",
            defaultAttr: {
              label: "出票日期",
              placeholder: "请填写出票日期",
              colWidthCount: 2,
            },
          },
          {
            type: "input",
            prop: "dftAppActno",
            defaultAttr: {
              label: "申请人账号",
              placeholder: "请填写申请人账号",
              colWidthCount: 2,
            },
          },
          {
            type: "input",
            prop: "dftCtgy",
            defaultAttr: {
              label: "票据种类",
              placeholder: "请填写票据种类",
              colWidthCount: 2,
            },
          },
          {
            type: "input",
            prop: "dftAppName",
            defaultAttr: {
              label: "申请人名称",
              placeholder: "请填写申请人名称",
              colWidthCount: 2,
            },
          },
          {
            type: "number",
            prop: "dftAppActno",
            defaultAttr: {
              label: "出票金额",
              placeholder: "请填写出票金额",
              colWidthCount: 2,
            },
          },
          {
            type: "number",
            prop: "dftStAmt",
            defaultAttr: {
              label: "实际结算金额",
              placeholder: "请填写实际结算金额",
              colWidthCount: 2,
            },
          },
          {
            type: "number",
            prop: "dftOverAmt",
            defaultAttr: {
              label: "多余金额",
              placeholder: "请填写多余金额",
              colWidthCount: 2,
            },
          },
        ],
      },
    ];
    this.cardList = formConfigList;
    this.$set(this.form, "bizCtgyCode", this.busTypeList[0].value);
  },
  methods: {
    // 表单重置
    reset() {
      // this.resetForm("editForm");
      this.$set(this, "form", {});
    },
    close() {
      this.openState = true;
    },
    // 关闭回掉
    handleClose(done) {
      this.$confirm("确认关闭？")
        .then((_) => {
          this.reset();
          done();
        })
        .catch((_) => {
        });
    },

    bizTypeCodeChange(code) {
      //联动修改bizCtgyCode
      let dictKeyPre = `BIZ_CTGY_HVPS_${code}`;
      this.getDicts(dictKeyPre).then((response) => {
        this.busTypeList = response.result;
        this.$set(this.form, "bizCtgyCode", this.busTypeList[0].value);
      });

      //画面输入要素修改------------------
      if (code == "A202") {
        //城市商业银行汇票
        this.$set(this.form, "payeeBrno", "904290099992");
        this.$set(this.form, "payeeName", "城银清算服务有限责任公司");
        this.$set(this.form, "payeeAccBrno", "904290099992");
        this.$set(this.form, "payeeAccBrName", "城银清算服务有限责任公司");
        this.$set(this.rules.payeeActno[0], "required", false);
        this.$set(this.rules.payeeName[0], "required", false);
        this.$set(this.rules.payeeAccBrno[0], "required", false);
      }
      if (code !== "A202") {
        this.$set(this.rules.payeeActno[0], "required", true);
        this.$set(this.rules.payeeName[0], "required", true);
        this.$set(this.rules.payeeAccBrno[0], "required", true);
      }
      if (code !== "A102") {
        this.$set(this.rules.remarksAll[0], "required", false);
      }
      if (code == "A102") {
        this.$set(this.rules.remarksAll[0], "required", true);
      }
    },
    actNoInfoCallback(refObj, actNoType) {
      console.log("actNoInfoCallback", actNoType);
      this.form.userInfo = {brno: "676"};
      let tempForm = refObj.form;
      console.log("tempForm", tempForm);
      if (actNoType === "payeeActno") {
        let actNo = this.form.payeeActno;
        console.log("actNo", actNo);
        getOtherCustByActno(actNo).then((response) => {
          console.log("response", response);
          if (response.code == "S" && response.result !== undefined) {
            this.$set(tempForm, "payeeActno", response.result.actNo);
            this.$set(tempForm, "payeeName", response.result.name);
            this.$set(this.form, "payeeBrno", response.result.rcvBrno);
            if (response.result.rcvBrname) {
              this.$set(tempForm, "payeeName", response.result.rcvBrname);
            }
            if (response.result.addr) {
              this.$set(tempForm, "payeeAddr", response.result.addr);
            }
            this.$set(this.form, "payeeAccBrno", response.result.accBrno);
            this.$set(tempForm, "payeeAccBrName", response.result.accBrnoName);
            console.log(tempForm, "tempForm");
          } else {
            this.msgSuccess("无历史付款记录");
            this.$set(tempForm, "payeeName", null);
            this.$set(this.form, "payeeBrno", null);
            this.$set(tempForm, "payeeName", null);
            this.$set(tempForm, "payeeAddr", null);
            this.$set(this.form, "payeeAccBrno", null);
            this.$set(tempForm, "payeeAccBrName", null);
          }
        });
      } else {
        let actNo = this.form.payerActno;
        getCustByActno(actNo).then((response) => {
          console.log("response", response);
          if (response.code == "S" && response.result !== undefined) {
            this.$set(tempForm, "payerActno", response.result.actNo);
            this.$set(tempForm, "payerName", response.result.name);
            this.$set(tempForm, "payerAddr", response.result.addr);
          } else {
            this.msgSuccess("查无此账号");
            this.$set(tempForm, "payerName", null);
            this.$set(tempForm, "payerAddr", null);
          }
        });
      }
    },
    // 回车查证账号信息
    actNoInfo(actNoType) {
      this.form.userInfo = {brno: "676"};
      let tempForm = refObj.form;
      if (actNoType === "payeeActNo") {
        let actNo = this.form.payeeActno;
        getOtherCustByActno(actNo).then((response) => {
          if (response.code == "S" && response.result !== undefined) {
            this.$set(tempForm, "payeeActno", response.result.actNo);
            this.$set(tempForm, "payeeName", response.result.name);
            this.$set(tempForm, "payeeBrno", response.result.rcvBrno);
            this.$set(tempForm, "payeeName", response.result.rcvBrname);
            this.$set(tempForm, "payeeAddr", response.result.addr);
            this.$set(tempForm, "payeeAccBrno", response.result.accBrno);
            this.$set(tempForm, "payeeAccBrName", response.result.accBrnoName);
          } else {
            this.msgSuccess("无历史付款记录");
            this.$set(tempForm, "payeeName", null);
            this.$set(tempForm, "payeeBrno", null);
            this.$set(tempForm, "payeeName", null);
            this.$set(tempForm, "payeeAddr", null);
            this.$set(tempForm, "payeeAccBrno", null);
            this.$set(tempForm, "payeeAccBrName", null);
          }
        });
      } else {
        let actNo = this.form.payerActno;
        getCustByActno(actNo).then((response) => {
          if (response.code == "S" && response.result !== undefined) {
            this.$set(tempForm, "payerActno", response.result.actNo);
            this.$set(tempForm, "payerName", response.result.name);
            this.$set(tempForm, "payerAddr", response.result.addr);
          } else {
            this.msgSuccess("查无此账号");
            this.$set(tempForm, "payerName", null);
            this.$set(tempForm, "payerAddr", null);
          }
        });
      }
    },
    // 检查大额交易金额上限
    checkAmountLimit() {
      isLessThenHvpsMinLimitNew(this.form.bizTypeCode, this.form.bizCtgyCode, this.form.bizPriority, this.form.amount);
    },
    confirmBankBranch(fromFlag, row, refObj) {
      console.log("fromFlag", fromFlag);
      console.log("confirmBankBranch", row);
      let tempForm = refObj.form;
      if (fromFlag == "payeeBrno") {
        this.$set(this.form, "payeeBrno", row.bankCode);
        this.$set(tempForm, "payeeBrno", row.bankCode);
        this.$set(tempForm, "payeeName", row.orgFullname);
      } else if (fromFlag == "payerAccBrno") {
        this.$set(this.form, "payerAccBrno", row.bankCode);
        this.$set(tempForm, "payerAccBrno", row.bankCode);
        this.$set(tempForm, "payerAccBrName", row.orgFullname);
      } else if (fromFlag == "payerBrno") {
        this.$set(this.form, "payerBrno", row.bankCode);
        this.$set(tempForm, "payerBrno", row.bankCode);
        this.$set(tempForm, "payerBrName", row.orgFullname);
      } else if (fromFlag == "payeeAccBrno") {
        this.$set(this.form, "payeeAccBrno", row.bankCode);
        this.$set(tempForm, "payeeAccBrno", row.bankCode);
        this.$set(tempForm, "payeeAccBrName", row.orgFullname);
      } else if (fromFlag == "agency1") {
        this.$set(this.form, "agency1", row.bankCode);
        this.$set(tempForm, "agency1", row.bankCode);
        this.$set(tempForm, "agency1name", row.orgFullname);
      } else if (fromFlag == "agency2") {
        this.$set(this.form, "agency2", row.bankCode);
        this.$set(tempForm, "agency2", row.bankCode);
        this.$set(tempForm, "agency2name", row.orgFullname);
      }
    },
    //回车取行号信息
    getBankInf(refObj, actNoType) {
      let tempForm = refObj.form;
      switch (actNoType) {
        case "payerBrno":
          getBankInfByBankCode(this.form.payerBrno).then((response) => {
            if (response.code == "S" && response.result !== undefined) {
              this.$set(tempForm, "payerBrno", response.result.bankCode);
              this.$set(tempForm, "payerBrName", response.result.orgFullname);
            } else {
              this.msgSuccess("查无此行号");
              this.$set(tempForm, "payerBrName", null);
            }
          });
          break;
        case "payerAccBrno":
          getBankInfByBankCode(this.form.payerAccBrno).then((response) => {
            if (response.code == "S" && response.result !== undefined) {
              this.$set(tempForm, "payerAccBrno", response.result.bankCode);
              this.$set(tempForm, "payerAccBrName", response.result.orgFullname);
            } else {
              this.msgSuccess("查无此行号");
              this.$set(tempForm, "payerAccBrName", null);
            }
          });
          break;
        case "payeeBrno":
          getBankInfByBankCode(this.form.payeeBrno).then((response) => {
            if (response.code == "S" && response.result !== undefined) {
              this.$set(tempForm, "payeeBrno", response.result.bankCode);
              this.$set(tempForm, "payeeName", response.result.orgFullname);
            } else {
              this.msgSuccess("查无此行号");
              this.$set(tempForm, "payeeName", null);
            }
          });
          break;
        case "payeeAccBrno":
          getBankInfByBankCode(this.form.payeeAccBrno).then((response) => {
            if (response.code == "S" && response.result !== undefined) {
              this.$set(tempForm, "payeeAccBrno", response.result.bankCode);
              this.$set(tempForm, "payeeAccBrName", response.result.orgFullname);
            } else {
              this.msgSuccess("查无此行号");
              this.$set(tempForm, "payeeAccBrName", null);
            }
          });
          break;
        case "agency1":
          getBankInfByBankCode(this.form.agency1).then((response) => {
            if (response.code == "S" && response.result !== undefined) {
              this.$set(tempForm, "agency1", response.result.bankCode);
              this.$set(tempForm, "agency1name", response.result.orgFullname);
            } else {
              this.msgSuccess("查无此行号");
              this.$set(tempForm, "agency1name", null);
            }
          });
          break;
        case "agency2":
          getBankInfByBankCode(this.form.agency2).then((response) => {
            if (response.code == "S" && response.result !== undefined) {
              this.$set(tempForm, "agency2", response.result.bankCode);
              this.$set(tempForm, "agency2name", response.result.orgFullname);
            } else {
              this.$set(tempForm, "agency2name", null);
            }
          });
          break;
      }
    },
    confirmPayee(fromFlag, row, refObj) {
      let tempForm = refObj.form;
      if (fromFlag == "payeeActno") {
        this.$set(this.form, "payeeActno", row.actNo);
        this.$set(tempForm, "payerActno", row.actNo);
        this.$set(tempForm, "payeeName", row.name);
        this.$set(tempForm, "payeeBrno", row.rcvBrno);
        this.$set(tempForm, "payeeName", row.rcvBrname);
        this.$set(tempForm, "payeeAddr", row.addr);
        this.$set(tempForm, "payeeAccBrno", row.accBrno);
        this.$set(tempForm, "payeeAccBrName", row.accBrnoName);
      }
    },
    confirmPayer(fromFlag, row, refObj) {
      console.log("confirmPayer", row);
      let tempForm = refObj.form;
      if (fromFlag == "payerActno") {
        this.$set(this.form, "payerActno", row.actNo);
        this.$set(tempForm, "payerActno", row.actNo);
        this.$set(tempForm, "payerName", row.name);
        this.$set(tempForm, "payerAddr", row.addr);
      }
    },
    show(id = "", pkgNo = "") {
      this.reset();
      this.pkgNo = pkgNo;
      this.id = id;
      this.title = "大额客户发起汇兑录入";
      this.$set(this.form, "payerBrno", this.globalBusData.cnapsBrno); //付款行号初始化当前操作员所以机构
      this.$set(this.form, "payerBrName", this.globalBusData.cnapsBrname);
      // 初始化设置;
      this.$set(this.form, "payeeBrno", "904290099992");
      this.$set(this.form, "payeeName", "城银清算服务有限责任公司");
      this.$set(this.form, "payeeAccBrno", "904290099992");
      this.$set(this.form, "payeeAccBrName", "城银清算服务有限责任公司");
      if (id) {
        this.title = "大额客户发起汇兑修改";

        // 如果传了ID 这里查询一个已经存在的数据
        detail({
          coreId: this.id,
          pkgNo: this.pkgNo,
        }).then((res) => {
          this.$set(this, "form", res.result.detail6401DataModel);
          this.openState = true;
        });
      } else {
        this.openState = true;
      }
    },

    cancel() {
      this.openState = false;
      this.reset();
      this.$emit("editComplete", false);
    },
    submitCheck(res) {
      if (res.code === "C") {
        this.$confirm(res.message, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.submitForm(res.result);
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消执行'
          });
          return;
        });
      }
    },
    /** TODO提交按钮 */
    submitForm: function (pass) {
      let formData = this.$refs.cardForm.getFormData();
      formData.pass = pass;
      console.log("formData", formData);
      //如果有ID 则是修改
      if (this.id) {
        formData.id = this.id;
        formData.userInfo = {brno: "676", userId: "cpg001"};
        updTxn(formData).then((res) => {
          this.submitCheck(res);
          if (res.code === "S") {
            this.msgSuccess("修改成功");
            this.$emit("editComplete", true);
            this.openState = false;
          }
        });
      } else {
        formData.userInfo = {brno: "676", userId: "cpg001"};
        addTxn(formData).then((res) => {
          this.submitCheck(res);
          if (res.code === "S") {
            this.msgSuccess("新增成功");
            this.$alert(`CORE_ID: ${res.result.rspId}`, "生成交易流水号", {
              confirmButtonText: "确定",
              //刷新一下查询列表 TODO
              callback: (action) => {
              },
            });
            this.$emit("editComplete", true);
            this.openState = false;
          }
        });
      }
      // this.$refs["editForm"].validate((valid) => {
      //
      //   if (valid) {
      //     let formData = this.$refs.cardForm.getFormData();
      //     //如果有ID 则是修改
      //     if (this.id) {
      //       formData.id = this.id
      //       formData.userInfo = { brno: "676", userId: "cpg001" };
      //       updTxn(formData).then((res) => {
      //         this.msgSuccess("修改成功");
      //         this.$emit("editComplete", true);
      //         this.openState = false;
      //       });
      //     } else {
      //       formData.userInfo = { brno: "676", userId: "cpg001" };
      //       addTxn(formData).then((res) => {
      //         this.msgSuccess("新增成功");
      //         this.$alert(`CORE_ID: ${res.result.rspId}`, "生成交易流水号", {
      //           confirmButtonText: "确定",
      //           //刷新一下查询列表 TODO
      //           callback: (action) => {},
      //         });
      //         this.$emit("editComplete", true);
      //         this.openState = false;
      //       });
      //     }
      //   }
      // });
    },
    /** 删除 按钮 */
    delTran: function () {
      if (this.id) {
        delTxn({id: this.id}).then((res) => {
          this.form.userInfo = {brno: "676", userId: "cpg001"};

          this.msgSuccess("修改成功");
          this.openState = false;
          this.$emit("editComplete", true);
        });
      }
    },
  },
};
</script>
<style>
.label-header-msg {
  font-weight: bold;
}

.form-card {
  margin-bottom: 10px;
}
</style>
